#include "sqlite.hpp"
#include <cassert>

int select_stu_callback(void *arg, int col_count, char **result, char **fields_name)
{
    std::vector<std::string> *args = (std::vector<std::string>*)arg;
    args->push_back(result[0]);
    return 0; // 返回0表示正常，非0表示异常，所以这里必须返回
}

int main()
{
    sqlitehelper helper("./test.db");
    // 1. 创建/打开库文件
    assert(helper.open());
    // 2. 创建表（不存在则创建）， 学生信息： 学号，姓名，年龄
    const char *st = "create table if not exists student(id int primary key,name varchar(20),age int);";
    helper.exec(st, nullptr, nullptr);
    // 3. 新增数据 ， 修改， 删除， 查询
    // const char* insert_sql = "insert into student values(3,'艾莉丝',20);";
    // helper.exec(insert_sql,nullptr,nullptr);

    // const char* updata_sql = "update student set age='21' where name='艾莉丝'";
    // helper.exec(updata_sql,nullptr,nullptr);

    // const char* delete_sql = "delete from student where name='艾莉丝'";
    // helper.exec(delete_sql,nullptr,nullptr);

    const char *select_sql = "select name from student;";
    std::vector<std::string> args;
    helper.exec(select_sql, select_stu_callback, &args);
    for (auto &name : args)
    {
        std::cout << name << std::endl;
    }
    // 4. 关闭数据库
    helper.close();
    return 0;
}